/**
 * PV 页面采集功能
 */
class PVCollector {
  // 家辅事件
  static STU_EVENT_ID = {
    RMS_COURSE_SYNC_SUBJECT: 'rms_course_sync_subject', // 家辅同步培优
    RMS_COURSE_SPECIAL_SUBJECT: 'rms_course_special_subject', // 家辅专项课程
    RMS_COURSE_PLAY: 'rms_course_play',
    RMS_SYNCLESSION_TEACH_PLAY: 'rms_synclession_teach_play',
    RMS_LITERACY: 'menu_stu_rms_s_literacyDevpt'
  };

  // 授课标识
  static teachingPackages = [
    'rms_synclession_package_delete',
    'rms_synclession_package_download',
    'rms_synclession_package_interaction',
    'rms_synclession_package_paper',
    'rms_synclession_package_play',
    'rms_synclession_package_recover',
    'rms_synclession_package_sort',
    'rms_synclession_package_upload',
    'rms_teachcloud_package_upload'
  ];

  // 播放PV采集
  // 使用 js sdk
  static getNewPVCollectParam (item, actionType) {
    const param = {};
    param.rcode = item.id || item.resId || item.fileId || '';
    param.bytes_count = item.size || 0;
    param.client_type = 'PC';
    param.play_duration = item.duration || 0;
    param.rformat = item.pcExtension || item.extension;
    param.data_type = 'resource_hot';
    param.sceneType = 0;
    if (localStorage.getItem('claInfo')) {
      const calInfo = JSON.parse(localStorage.getItem('claInfo'));
      if (calInfo && calInfo.id && calInfo.parentId) {
        param.catalogueId = calInfo.parentId;
        param.bookId = calInfo.bookId;
      }
    } else {
      param.catalogueId = '0';
      param.bookId = '0';
    }
    var __VAE__ = window.__VAE__;
    if (__VAE__) {
      __VAE__.customEvent(actionType, param);
    }
  }

  static getNormalStaticParam (actionType, { resInfo, calInfo, data_type } = {}) {
    const param = {};
    if (resInfo) {
      param.rcode = resInfo.id || resInfo.resId || resInfo.fileId || ''; // 资源id
      param.bytes_count = resInfo.size || 0; //  资源大小
      param.play_duration = resInfo.duration || 0; // 资源时长
      param.rformat = resInfo.pcExtension || resInfo.extension;
      param.data_type = 'resource_hot';
    }
    if (calInfo) {
      if (calInfo && calInfo.catalogueId) {
        param.catalogueId = calInfo.catalogueId;
        param.bookId = calInfo.bookId;
      }
    } else {
      param.catalogueId = '0';
      param.bookId = '0';
    }
    if (PVCollector.teachingPackages.indexOf(actionType) !== -1) {
      param.sceneType = 1;
    } else {
      param.sceneType = 0;
    }
    param.client_type = 'Mobile';
    if (data_type) {
      param.data_type = data_type;
    } else {
      param.data_type = 'resource_hot';
    }
    var __VAE__ = window.__VAE__;
    if (__VAE__) {
      __VAE__.customEvent(actionType, param);
    }
  }
}

export default PVCollector;
